package com.test.antlr4.sql;

import com.test.antlr4.sql.core.SQLLexer;
import com.test.antlr4.sql.core.SQLParser;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.tree.ParseTree;

/**
 * 测试
 *
 * @author  2021/12/23
 */
public class SqlMain {
    public static void main(String[] args) {
        String sql = "select name,age,job from t_user";
        SQLLexer mySqlLexer = new SQLLexer(CharStreams.fromString(sql));
        CommonTokenStream commonTokenStream = new CommonTokenStream(mySqlLexer);
        SQLParser mySqlParser = new SQLParser(commonTokenStream);
        SQLParser.SelectStatementContext selectStatementContext = mySqlParser.selectStatement();
        for (ParseTree child : selectStatementContext.children) {
            System.out.println(child.getText());
        }
    }
}
